home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / stretch.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  120 lines

  1. ; $Id: stretch.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1983-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. Pro Stretch, Low, High, Gamma, CHOP = Chop
  7. ;+
  8. ; NAME:
  9. ;    STRETCH
  10. ;
  11. ; PURPOSE:
  12. ;    Stretch the image display color tables so the full range 
  13. ;    runs from one color index to another.
  14. ;
  15. ; CATEGORY:
  16. ;    Image processing, point operations.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    STRETCH, Low, High [, /CHOP]
  20. ;
  21. ; INPUTS:
  22. ;    Low:    The lowest pixel value to use.  If this parameter is omitted,
  23. ;        0 is assumed.  Appropriate values range from 0 to the number 
  24. ;        of available colors-1.
  25. ;
  26. ;    High:    The highest pixel value to use.  If this parameter is omitted,
  27. ;        the number of colors-1 is assumed.  Appropriate values range 
  28. ;        from 0 to the number of available colors-1.
  29. ;
  30. ; OPTIONAL INPUTS:
  31. ;    Gamma:    Gamma correction factor.  If this value is omitted, 1.0 is 
  32. ;        assumed.  Gamma correction works by raising the color indices
  33. ;        to the Gamma power, assuming they are scaled into the range 
  34. ;        0 to 1.
  35. ;
  36. ; KEYWORD PARAMETERS:
  37. ;    CHOP:    If this keyword is set, color values above the upper threshold
  38. ;        are set to color index 0.  Normally, values above the upper 
  39. ;        threshold are set to the maximum color index.
  40. ;
  41. ; OUTPUTS:
  42. ;    No explicit outputs.
  43. ;
  44. ; COMMON BLOCKS:
  45. ;    COLORS:    The common block that contains R, G, and B color
  46. ;        tables loaded by LOADCT, HSV, HLS and others.
  47. ;
  48. ; SIDE EFFECTS:
  49. ;    Image display color tables are loaded.
  50. ;
  51. ; RESTRICTIONS:
  52. ;    Common block COLORS must be loaded before calling STRETCH.
  53. ;
  54. ; PROCEDURE:
  55. ;    New R, G, and B vectors are created by linearly interpolating
  56. ;    the vectors in the common block from Low to High.  Vectors in the 
  57. ;    common block are not changed.
  58. ;
  59. ;    If NO parameters are supplied, the original color tables are
  60. ;    restored.
  61. ;
  62. ; EXAMPLE:
  63. ;    Load the STD GAMMA-II color table by entering:
  64. ;
  65. ;        LOADCT, 5
  66. ;
  67. ;    Create and display and image by entering:
  68. ;
  69. ;        TVSCL, DIST(300)
  70. ;
  71. ;    Now adjust the color table with STRETCH.  Make the entire color table
  72. ;    fit in the range 0 to 70 by entering:
  73. ;
  74. ;        STRETCH, 0, 70
  75. ;
  76. ;    Notice that pixel values above 70 are now colored white.  Restore the
  77. ;    original color table by entering:
  78. ;
  79. ;        STRETCH
  80. ;
  81. ; MODIFICATION HISTORY:
  82. ;    DMS, RSI, Dec, 1983.
  83. ;    DMS, April, 1987.    Changed common.
  84. ;    DMS, October, 1987.    For unix.
  85. ;    DMS, RSI, Nov., 1990.    Added GAMMA parameter.
  86. ;-
  87. ;
  88.     common colors,r,g,b,cur_red,cur_green,cur_blue
  89.     on_error,2        ;Return to caller if error
  90.     nc = !d.table_size    ;# of colors entries in device
  91.     if nc eq 0 then message, $
  92.         "Device has static color tables.  Can't modify.'
  93.  
  94.     if n_elements(r) le 0 then begin    ;color tables defined?
  95.         r=indgen(nc) & g=r & b=r & endif
  96.     if n_params(0) lt 1 then low = 0
  97.     if n_params(0) lt 2 then high = nc-1
  98.     if n_params(0) lt 3 then gamma = 1.0    ;Default gamma
  99.     if high eq low then return        ;Nonsensical
  100.  
  101.     if gamma eq 1.0 then begin        ;Simple case
  102.         slope = float(nc-1)/(high-low)  ;Scale to range of 0 : nc-1
  103.         intercept = -slope*low
  104.         p = long(findgen(nc)*slope+intercept) ;subscripts to select
  105.     endif else begin            ;Gamma ne 0
  106.         slope = 1. / (high-low)        ;Range of 0 to 1.
  107.         intercept = -slope * low
  108.         p = findgen(nc) * slope + intercept > 0.0
  109.         p = long(nc * (p ^ gamma))
  110.     endelse
  111.     if keyword_set(Chop) then begin
  112.         too_high = where(p ge nc, n)
  113.         if n gt 0 then p[too_high]  = 0L
  114.         endif
  115.     cur_red = r[p] & cur_green = g[p] & cur_blue = b[p]
  116.     tvlct,cur_red, cur_green, cur_blue
  117.     return
  118. end
  119.  
  120.